package org.example.web.service.impl;

import org.example.dao.mapper.UserMapper;
import org.example.dao.model.User;
import org.example.dao.model.UserExample;
import org.example.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> selectAll() {
        return userMapper.selectByExample(null);
    }

    @Override
    public User selectById(int id) {
        return userMapper.selectByPrimaryKey(id);
    }

    public List<User> getUserByName(String name) {
        UserExample example = new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameLike("%" + name + "%");
        return userMapper.selectByExample(example);
    }

    @Override
    public int addUser(User user) {
        return userMapper.insert(user);
    }

}
